package lib

import (
	"fmt"
	"math/rand"
	"strconv"
	"time"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/service/dynamodb"
)

func PutItem() {
	rand.Seed(time.Now().UnixNano())
	now := strconv.Itoa(int(time.Now().Unix()))
	count := strconv.Itoa(rand.Intn(9000))
	channel_id := "gotest" + strconv.Itoa(rand.Intn(88000))
	//从切片中，随机抽一个
	allStatus := []string{"living", "upcoming", "canceled", "ended"}
	status := allStatus[rand.Intn(len(allStatus))]
	_, err := DynamoClient.PutItem(&dynamodb.PutItemInput{
		Item: map[string]*dynamodb.AttributeValue{
			"channel_id": {
				S: aws.String(channel_id),
			},
			"count": {
				N: aws.String(count),
			},
			"schedule_time": {
				N: aws.String(now),
			},
			"status": {
				S: aws.String(status),
			},
		},
		TableName: aws.String("live"),
	})
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Printf("添加成功,channel_id:%s count:%s schedule_time:%s status:%s ", channel_id, count, now, status)
	}
}
